/**
 * 状态管理
 */
import order from './modules/order.js'
export const state = () => ({
	token:'null',
})

//同步处理
export const mutations = {
	setToken(state,data){
		state.token = data;
	},
  setUser(state,data){
  	state.user = data;
  }
}

//异步处理
export const actions = {
  //初始化store服务端要的一些数据
  async nuxtServerInit({ commit,state },{req}) {
    //服务端解析cookie
  	let cookies = req.headers.cookie?req.headers.cookie.split('; '):[];
  	cookies.some(item => {
  		let arr = item.split('=');
  		if(arr[0] === 'vuex'){
        //处理cookie中的内容
        let cookie = JSON.parse(decodeURIComponent(arr[1]))
        for(let key in cookie){
          state[key] = cookie[key]
        }
  		}
  	})
  }
}

//计算属性
export const getters = {

}

//其他模块
export const modules = {
  order
}
